/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.me.schedule;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import java.util.ArrayList;

/**
 *
 * @author peterholtegaard@gmail.com
 */
public class Month {
    public enum months{januar,februar, marts, april, maj, juni,juli,august,september,oktober,
    november, december};
    private months name;
    private int monthInYear;
    private ArrayList<Day> days;
    private Month(int monthInYear)
    {
        this.monthInYear = monthInYear;
        this.name = months.values()[monthInYear];
        days = new ArrayList<Day>();
    }

    public void addDay(Day day)
    {
        days.add(day);
    }
    public months getName()
    {
        return name;
    }

    public static Month getMonthFromTTVHtml(String html, int nr, Handler h)
    {
        Month month = new Month(nr - 1);//yeah, off by one bitch
        String[] lines = html.split("\n");
        int c = 0;
        for (int i = 0; i < lines.length; i++) {
            if (lines[i].contains("class=\"calempty\">") || lines[i].contains("calunack")) {
                Log.e("jeg fik", lines[i]);
                Day d = (Day.dayFromTTVString(lines[i], month.monthInYear));
                Bundle b = new Bundle();
                Message msg = h.obtainMessage();
                b.putCharSequence("day", d.toString());
                msg.setData(b);
                h.sendMessage(msg);
                month.days.add(d);
                c++;
            }
        }
        return month;
    }
    @Override
    public String toString()
    {
        StringBuilder str = new StringBuilder();
        for(Day d:days)
        {
            str.append(d.toString());
        }
        return str.toString();
    }

    public ArrayList<Day> getDays() {
        return days;
    }

    public int getMonthInYear() {
        return monthInYear;
    }



}
